package com.example.mytayunapi.Mapper;

import com.example.mytayunapi.Vo.ShareUserInfo;
import com.example.mytayunapi.Vo.ShareUserProducts;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Share_postsInfoMapper {

    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree")
    List<ShareUserInfo> getSharePostsInfo();

    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree WHERE Share_title Like #{Share_title}")
    List<ShareUserInfo> getShareTitleInfo(@Param("Share_title")String Share_title);

    @Update("UPDATE Share_posts s JOIN user u ON u.School_degree = s.School_degree SET s.Share_status = #{Share_status}, s.beizhu = #{beizhu},operator = #{operator} where s.Share_id = #{Share_id}")
    Integer updateShareStatus(ShareUserInfo shareUserInfo);

    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree where s.Share_status = #{Share_status}")
    List<ShareUserInfo> getSharePostsInfoStatus(@Param("Share_status")String Share_status);


    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree where s.Share_status != #{Share_status}")
    List<ShareUserInfo> getSharePostsInfoStatusNa(@Param("Share_status")String Share_status);

    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree where s.Share_title LIKE " +
            "CONCAT('%', #{keyword},'%') and s.Share_status = #{Share_status}")
    List<ShareUserInfo> getSharetitleAndWord(@Param("keyword")String keyword, @Param("Share_status")String Share_status);

    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree where s.Share_title LIKE CONCAT('%',#{keyword},'%')")
    List<ShareUserInfo> getShareTitle(@Param("keyword")String keyword);

    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree where s.Share_catagory LIKE CONCAT('%',#{word},'%')")
    List<ShareUserInfo> getShareTitleAndCate(@Param("word")String word);

    @Select("SELECT s.*,u.Nick_name FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree where s.Share_title LIKE " +
            "CONCAT('%',#{keyword},'%') and s.Share_catagory LIKE CONCAT('%',#{word},'%') and s.Share_status = '审核中'")
    List<ShareUserInfo> getShareTitleAndCateStatus(@Param("keyword")String keyword, @Param("word")String word);

    @Select("SELECT * FROM tayun.share_posts where Share_catagory = #{Share_catagory}")
    List<ShareUserInfo> getSharePosts(@Param("Share_catagory")String Share_catagory);

    @Select("SELECT * FROM Share_posts s JOIN user u ON u.School_degree = s.School_degree where Share_id = #{Share_id}")
    List<ShareUserInfo> getSharePostsDetail(@Param("Share_id")Integer Share_id);

    @Select("select * from share_posts where School_degree = (select School_degree from products where Product_id  = #{Product_id}) and Share_status = '通过'")
    List<ShareUserProducts> getShareUserProducts(@Param("Product_id")Integer Product_id);

    @Delete("DELETE FROM share_posts WHERE Share_id = #{Share_id}")
    Integer deleteSharePosts(@Param("Share_id") Integer Share_id);

    @Select("select * from share_posts where School_degree = #{School_degree}")
    List<ShareUserInfo> getSharePostsInfoByPeople(@Param("School_degree")String School_degree);
}
